import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Scene } from "../Scene";
import { oops } from "db://oops-framework/core/Oops";
import { RoleAttributeType, RoleModuleType } from "../../../role/model/RoleEnum";
import { BattleType } from "../SceneEvent";
import { smc } from "../../../common/ecs/SingletonModuleComp";
import { Skill } from "../../skill/Skill";
import { BattleEventTrigger } from "../../skill/bll/utils/BattleEventTrigger";

/**
 * 战斗开始
 */
@ecs.register('BattleStart')
export class BattleStartComp extends ecs.Comp {
    reset() {
    }
}
export class BattleStartSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
    filter(): ecs.IMatcher {
        return ecs.allOf(BattleStartComp);
    }

    entityEnter(e: Scene): void {
        oops.log.trace(`###第${e.BattleModel.daGuan}-${e.BattleModel.xiaoguan}关###`);
        e.MapModelRole.round = 1;

        //恢复50能量，清空所有buff,重置所有属性
        e.MapModelRole.friends.forEach(role => {
            // RoleBuff.removeAllBuff(role);
            role.removeAllNumericByType(RoleModuleType.Decorator);
            //RoleAttribute.cover(role, RoleAttributeType.power, 50);
        });

        var skill!: Skill;
        if (e.BattleModel.xiaoguan == 1) {
            //第一小关恢复血量跟能量
            skill = ecs.getEntity<Skill>(Skill);
            skill.SkillModel.id = 1;
        }

         BattleEventTrigger.onBattleStart(BattleType.Scene);

        smc.scene.play(() => {
            setTimeout(() => {
               skill?.cast(e.MapModelRole.friends[0]);
                e.roundStart();
                e.remove(BattleStartComp);
            }, 1000 / oops.game.getTimeScale());
        });
    }
}